package com.ztom.daily.n2022.m5;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 最近的请求次数
 * <p>
 * https://leetcode-cn.com/problems/number-of-recent-calls/
 *
 * @author ZhangTao
 */
public class Day07RecentCounter {

    class RecentCounter {

        private Queue<Integer> queue;

        public RecentCounter() {
            this.queue = new LinkedList<>();
        }

        public int ping(int t) {
            queue.offer(t);
            while (!queue.isEmpty() && queue.peek() < t - 3000) {
                queue.poll();
            }
            return queue.size();
        }
    }
}
